#include <tsin/library/DynamicSerialList.hpp>

#include <tsin/util/Logger.hpp>

using namespace tsin;

DynamicSerialList::DynamicSerialList()
        : current(0), ended(false)
{
}

DynamicObject *DynamicSerialList::copy()
{
        return DynamicObject::copy(new DynamicSerialList);
}

void DynamicSerialList::reinit()
{
        current = 0;
        ended = false;
        arguments[current]->reinit();
}

DynamicEvent DynamicSerialList::postTick(void *data, void *priv_data)
{
        if (ended)
                return EVENT_END;

        DynamicEvent event = arguments[current]->postTick(data, priv_data);
        if (event & EVENT_END) {
                if (current == nrArguments - 1) {
                        ended = true;
                        return EVENT_END;
                }
                current ++;
                arguments[current]->reinit();
        }
        return EVENT_REINIT;
}

char DynamicSerialList::getDescriptor()
{
        if (nrArguments == 0)
                return '?';
        return arguments[0]->getDescriptor();
}

int DynamicSerialList::getInt()
{
        return arguments[current]->getInt();
}

float DynamicSerialList::getFloat()
{
        return arguments[current]->getFloat();
}

bool DynamicSerialList::getBool()
{
        return arguments[current]->getBool();
}
